package com.sourceQ.system.controller.tenant;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sourceQ.common.core.domain.R;
import com.sourceQ.common.core.web.controller.BaseController;
import com.sourceQ.common.core.web.domain.AjaxResult;
import com.sourceQ.common.log.annotation.Log;
import com.sourceQ.common.log.enums.BusinessType;
import com.sourceQ.system.dto.tenant.TenantPageReqDTO;
import com.sourceQ.system.dto.tenant.TenantSaveReqDTO;
import com.sourceQ.system.vo.tenant.TenantVo;
import com.sourceQ.system.service.tenant.TenantService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author: SourceQ
 * @create: 2024-03-25 16:43
 * @Description:多租户管理
 */
@RestController
@RequestMapping(value = "/tenant")
@Api(tags = "租户管理")
public class TenantController extends BaseController {

    @Autowired
    private TenantService tenantService;

    @ApiOperation(value = "创建租户")
    @Log(title = "租户管理",businessType = BusinessType.INSERT)
    @PostMapping("/create")
    public AjaxResult create(@RequestBody TenantSaveReqDTO dto){
        return success(tenantService.createTenant(dto));
    }
    @ApiOperation(value = "租户修改")
    @Log(title = "租户管理",businessType = BusinessType.UPDATE)
    @PutMapping("/update")
    public AjaxResult update(@RequestBody TenantSaveReqDTO dto){
        tenantService.updateTenant(dto);
        return success();
    }
    @ApiOperation(value = "租户删除")
    @Log(title = "租户管理",businessType = BusinessType.DELETE)
    @DeleteMapping("/delete/{ids}")
    public AjaxResult delete(@PathVariable Long[] ids){
        tenantService.deleteTenant(ids);
        return success();
    }

    @ApiOperation(value = "租户详情")
    @GetMapping("/detail/{id}")
    public AjaxResult detail(@PathVariable Long id){
        return success(tenantService.getTenant(id));
    }

    @ApiOperation(value = "租户列表查询")
    @GetMapping("/page")
    public R<IPage<TenantVo>> page(Page page, TenantPageReqDTO dto){
        return R.ok(tenantService.getTenantPage(page,dto));
    }
    @ApiOperation(value = "修改租户状态")
    @Log(title = "租户管理",businessType = BusinessType.UPDATE)
    @GetMapping("/change-status")
    public AjaxResult updateTenantStatus(Long id,String status){
        tenantService.changeStatus(id,status);
        return success();
    }



}
